<template>
  <div class="web-big-search">
    <div class="header-search">
      <div class="web-search">
        <!-- sousuo -->
        <div class="search">
          <i class="iconfont icon-sousuo"></i>
          <input
            type="text"
            @keyup.enter="getEnter"
            v-model="v1"
            placeholder="流浪地球"
          />
        </div>
        <!--  -->
        <span @click="goBlack" class="search-txt">取消</span>
      </div>
      <!-- 历史搜索 -->
      <div class="history-sousuo" v-show="!loadState">
        <div class="his-list">
          <h3>历史搜索</h3>
          <span @click="clearHistory">删除</span>
        </div>
        <ul>
          <li v-for="(oe, oi) in historyArr" :key="oi">{{ oe }}</li>
        </ul>
      </div>
      <!-- 数据渲染 -->
      <!-- <div > -->
      <ul class="search-list" v-show="loadState">
        <li
          @click="slClick(li, le.path)"
          v-for="(le, li) in searchList"
          :key="li"
          :class="slIndex == li ? 'active' : ''"
        >
          {{ le.name }}
        </li>
      </ul>
    </div>
    <!-- 动态路由 -->
    <div class="search-nav">
      <keep-alive>
        <component v-bind:msg="msg" :is="slName"></component>
      </keep-alive>
    </div>
  </div>
</template>
<script>
import cartAll from "../cartsearch/cart-all.vue";
import cartCinema from "../cartsearch/cart-cinema.vue";
import cartFilm from "../cartsearch/cart-film.vue";
import { mapState, mapMutations } from "vuex";

export default {
  name: "search",
  data() {
    return {
      moviesData: [], //搜索到的数据
      cinemasData: [], //搜索到的数据  影院
      v1: "",
      msg: "",
      loadState: false, //loading状态

      searchList: [
        { name: "综合", path: "cartAll" },
        { name: "影院", path: "cartCinema" },
        { name: "影视", path: "cartFilm" },
      ],
      slIndex: 0,
      slName: "cartAll",
      // 历史搜索
      historyArr: [],
    };
  },
  components: {
    cartAll,
    cartCinema,
    cartFilm,
  },
  watch: {
    msg(value) {
      this.historyArr.push(value);
      this.searchData();
    },
  },
  methods: {
    ...mapMutations(["changeHistoryArray"]),
    searchData() {
      this.changeHistoryArray(this.historyArr);
      // console.log(this.$store.state.historyArray);
    },
    clearHistory() {
      this.changeHistoryArray([]);
      this.historyArr = [];
    },
    slClick(k, p) {
      this.slIndex = k;
      this.slName = p;
      // console.log(k, p);
    },
    goBlack() {
      this.$router.go(-1);
    },
    getEnter() {
      this.msg = this.v1;
      this.loadState = true;
    },
  },
  mounted() {
    this.historyArr = this.$store.state.historyArray || [];
    // this.getData();
  },
};
</script>
<style lang="scss" scoped>
.web-big-search {
  width: 100%;
  background: #ffffff;
  min-height: 812px;
}
.header-search {
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 99;
  background: #fff;
}
.search-nav{
  margin-top: 100px;
}
.web-search {
  width: 343px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.search {
  width: 272px;
  height: 44px;
  position: relative;
  display: flex;
  align-items: center;
  i {
    font-size: 18px;
    width: 20px;
    height: 44px;
    line-height: 44px;
    position: absolute;
    left: 10px;
    color: #ccc;
  }
  input {
    width: 272px;
    height: 36px;
    border-radius: 20px;
    border: 1px solid #f5f5f5;
    background: #f5f5f5;
    box-sizing: border-box;
    text-indent: 30px;
    font-size: 12px;
  }
}
.search-txt {
  font-size: 18px;
  color: #323233;
  font-weight: 500;
  padding: 0 10px;
}
// 历史搜索
.history-sousuo {
  width: 375px;
  // background: #f8f8f8;
  display: flex;
  flex-direction: column;

  .his-list {
    width: 343px;
    margin: 20px auto 10px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    > h3 {
      font-size: 16px;
    }
    > span {
      font-size: 14px;
    }
  }

  > ul {
    width: 343px;
    margin: 0 auto 30px;
    display: flex;
    flex-wrap: wrap;
    margin-top: 10px;
    li {
      padding: 4px 8px;
      border-radius: 4px;
      margin-right: 10px;
      margin-bottom: 5px;
      font-size: 10px !important;
      background: #ececec;
      color: #818181;
    }
  }
}
// 列表项
.search-list {
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 10px 0;
 border-bottom: 1px solid rgb(241, 241, 241);
  li {
    font-size: 20px;
    transition: all .1s;
  }
  .active {
    // font-weight: bold;
    // font-size: 22px;
    transform: scale(1.1);
    color: rgb(255, 61, 61);
  }
}
</style>